package com.xyyl.patient.service.evaluating;

import com.xyyl.patient.core.support.Pager;
import com.xyyl.patient.entity.evaluating.Evaluating;
import com.xyyl.patient.entity.evaluating.EvaluatingQuestionVO;
import com.xyyl.patient.entity.evaluating.EvaluatingType;
import com.xyyl.patient.entity.evaluating.EvaluatingUser;
import com.xyyl.patient.mapper.evaluating.EvaluatingMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @projectName:xyyl-oms-server
 * @ClassName: Evaluating
 * @Description:Evaluating
 * @author chens
 * @date 2018-01-03 14:41:05
 */
@Service("evaluatingService")
public class EvaluatingServiceImpl implements EvaluatingService {

	@Autowired
	private EvaluatingMapper evaluatingMapper;


	@Override
	@Transactional
	public Evaluating queryObject(Integer id) {
		return evaluatingMapper.selectOne(id);
	}

	@Override
	@Transactional
	public List<EvaluatingType> getEvaluatingCategories() {

		return evaluatingMapper.selectList(new EvaluatingType());
	}
	@Override
	@Transactional
	public List<Evaluating> getEvaluating(Pager pager){

		return evaluatingMapper.queryForPage(pager);
	}
	@Override
	@Transactional
	public List<Evaluating> getEvaluatingByUser(Integer id){

		return evaluatingMapper.getEvaluatingByUser(id);
	}
	@Override
	@Transactional
	public int saveEvaluating(Evaluating EvaluatingEntity) {

		return evaluatingMapper.insert(EvaluatingEntity);
	}

	@Override
	@Transactional
	public List<EvaluatingQuestionVO> getEvaluatingQuestion(Integer id){
		return evaluatingMapper.selectEvaluatingQuestionList(id);
	}
	@Override
	@Transactional
	public int addEvaluatingAnswer(){
		return 0;
	}

	@Override
	@Transactional
	public Evaluating getEvaluatingAnswer(Integer EvaluatingId, Integer score){

		return evaluatingMapper.selectEvaluatingAnswer( EvaluatingId,  score);
	}
	@Override
	@Transactional
	public int setEvaluatingAnswer(EvaluatingUser evaluatingUser){
		Evaluating evaluating = new Evaluating();
		evaluating.setId(evaluatingUser.getEvaluatingId());
		Evaluating evaluating1 =evaluatingMapper.selectOne(evaluatingUser.getEvaluatingId());
		evaluating.setParticipantcount(evaluating1.getParticipantcount()+1);
		evaluatingMapper.update(evaluating);
		return evaluatingMapper.addEvaluatingUser(evaluatingUser);
	}

	@Override
	@Transactional
	public int updateEvaluating(Evaluating EvaluatingEntity) {
	 
		return evaluatingMapper.update(EvaluatingEntity);
	}

	    
	@Override
	@Transactional
	public int deleteEvaluating(Integer id) {
		return evaluatingMapper.delete(id);
	}

 
	    
	@Override
	@Transactional
	public int batchDeleteEvaluating(Integer[] ids) {
		
		return 0;
	}
}
